<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>课堂随机抽人系统</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #1a2a6c, #b21f1f, #1a2a6c);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 20px;
            color: #fff;
            background-size: 400% 400%;
            animation: gradientBG 15s ease infinite;
        }
        
        @keyframes gradientBG {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }
        
        .container {
            width: 100%;
            max-width: 800px;
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(12px);
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            padding: 30px;
            margin-top: 20px;
            border: 1px solid rgba(255, 255, 255, 0.2);
        }
        
        header {
            text-align: center;
            margin-bottom: 30px;
        }
        
        h1 {
            font-size: 2.8rem;
            margin-bottom: 10px;
            text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
            background: linear-gradient(to right, #ffd700, #ffa500);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 15px;
        }
        
        .description {
            font-size: 1.2rem;
            opacity: 0.9;
            max-width: 600px;
            margin: 0 auto;
            line-height: 1.6;
        }
        
        .card {
            background: rgba(255, 255, 255, 0.15);
            border-radius: 15px;
            padding: 25px;
            margin-bottom: 30px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .card-title {
            font-size: 1.6rem;
            margin-bottom: 20px;
            display: flex;
            align-items: center;
            gap: 10px;
            color: #ffd700;
        }
        
        .input-group {
            margin-bottom: 25px;
        }
        
        label {
            display: block;
            margin-bottom: 10px;
            font-size: 1.1rem;
            font-weight: 500;
        }
        
        textarea {
            width: 100%;
            height: 180px;
            padding: 15px;
            border-radius: 12px;
            border: 2px solid rgba(255, 255, 255, 0.3);
            background: rgba(0, 0, 0, 0.2);
            color: white;
            font-size: 1.1rem;
            resize: vertical;
            transition: all 0.3s ease;
        }
        
        textarea:focus {
            outline: none;
            border-color: #4cc9f0;
            box-shadow: 0 0 0 3px rgba(76, 201, 240, 0.3);
        }
        
        .example-text {
            font-size: 0.95rem;
            opacity: 0.8;
            margin-top: 8px;
            padding: 0 5px;
            font-style: italic;
        }
        
        .settings {
            display: flex;
            flex-wrap: wrap;
            gap: 25px;
            margin: 25px 0;
        }
        
        .setting-item {
            flex: 1;
            min-width: 200px;
        }
        
        select {
            width: 100%;
            padding: 14px;
            border-radius: 12px;
            border: 2px solid rgba(255, 255, 255, 0.3);
            background: rgba(0, 0, 0, 0.2);
            color: white;
            font-size: 1.1rem;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        
        select:focus {
            outline: none;
            border-color: #4cc9f0;
            box-shadow: 0 0 0 3px rgba(76, 201, 240, 0.3);
        }
        
        .button-group {
            display: flex;
            justify-content: center;
            gap: 20px;
            flex-wrap: wrap;
            margin-top: 20px;
        }
        
        .btn {
            padding: 16px 36px;
            border: none;
            border-radius: 50px;
            font-size: 1.2rem;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
        }
        
        .btn-primary {
            background: linear-gradient(to right, #4facfe, #00f2fe);
            color: white;
        }
        
        .btn-secondary {
            background: rgba(255, 255, 255, 0.15);
            color: white;
            border: 2px solid rgba(255, 255, 255, 0.3);
        }
        
        .btn:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
        }
        
        .btn:active {
            transform: translateY(2px);
        }
        
        .result-container {
            display: none;
            text-align: center;
            padding: 20px;
        }
        
        .result-title {
            font-size: 2.2rem;
            margin-bottom: 40px;
            color: #ffd700;
            text-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
        }
        
        .result-display {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 25px;
            margin-bottom: 40px;
        }
        
        .result-item {
            background: linear-gradient(135deg, #f6d365, #fda085);
            color: #2c3e50;
            font-size: 2.5rem;
            font-weight: bold;
            padding: 35px 50px;
            border-radius: 15px;
            min-width: 220px;
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
            animation: popIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
            position: relative;
            overflow: hidden;
        }
        
        .result-item::after {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(120deg, 
                rgba(255,255,255,0.1), 
                rgba(255,255,255,0.3), 
                rgba(255,255,255,0.1));
            z-index: 1;
            animation: shine 3s infinite;
        }
        
        @keyframes popIn {
            0% { transform: scale(0.5) rotate(-10deg); opacity: 0; }
            100% { transform: scale(1) rotate(0); opacity: 1; }
        }
        
        @keyframes shine {
            0% { transform: translateX(-100%); }
            20% { transform: translateX(100%); }
            100% { transform: translateX(100%); }
        }
        
        .spinning {
            animation: spin 0.5s linear infinite;
        }
        
        @keyframes spin {
            100% { transform: rotate(360deg); }
        }
        
        footer {
            margin-top: 30px;
            text-align: center;
            font-size: 1rem;
            opacity: 0.8;
            padding: 15px;
        }
        
        /* 响应式设计 */
        @media (max-width: 768px) {
            .container {
                padding: 20px;
            }
            
            h1 {
                font-size: 2.2rem;
            }
            
            .settings {
                flex-direction: column;
                gap: 20px;
            }
            
            .result-item {
                font-size: 1.8rem;
                padding: 25px 35px;
                min-width: 180px;
            }
            
            .btn {
                padding: 14px 28px;
                font-size: 1.1rem;
                width: 100%;
            }
            
            .button-group {
                flex-direction: column;
            }
        }
        
        @media (max-width: 480px) {
            h1 {
                font-size: 1.8rem;
            }
            
            .result-item {
                font-size: 1.5rem;
                padding: 20px 30px;
            }
            
            .card-title {
                font-size: 1.4rem;
            }
        }
        
        /* 装饰元素 */
        .decoration {
            position: absolute;
            width: 100px;
            height: 100px;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 50%;
            z-index: -1;
        }
        
        .decoration:nth-child(1) {
            top: 10%;
            left: 10%;
            animation: float 8s ease-in-out infinite;
        }
        
        .decoration:nth-child(2) {
            top: 20%;
            right: 15%;
            width: 70px;
            height: 70px;
            animation: float 10s ease-in-out infinite;
        }
        
        .decoration:nth-child(3) {
            bottom: 15%;
            left: 15%;
            width: 50px;
            height: 50px;
            animation: float 12s ease-in-out infinite;
        }
        
        @keyframes float {
            0% { transform: translateY(0) rotate(0); }
            50% { transform: translateY(-20px) rotate(180deg); }
            100% { transform: translateY(0) rotate(360deg); }
        }
    </style>
</head>
<body>
    <!-- 背景装饰元素 -->
    <div class="decoration"></div>
    <div class="decoration"></div>
    <div class="decoration"></div>
    
    <div class="container">
        <header>
            <h1><i class="fas fa-random"></i> 课堂随机抽人系统</h1>
            <p class="description">公平、随机、高效的课堂点名工具，让课堂互动更加生动有趣</p>
        </header>
        
        <div class="card">
            <h2 class="card-title"><i class="fas fa-users"></i> 名单设置</h2>
            
            <div class="input-group">
                <label for="nameList">输入名单（支持逗号分隔、换行分隔或学号范围如1-40）：</label>
                <textarea id="nameList" placeholder="例如：
张三, 李四, 王五
或
1-40
或
小明
小红
小刚">张三, 李四, 王五, 赵六, 钱七, 孙八, 周九, 吴十, 郑十一, 王十二, 刘十三, 陈十四, 杨十五, 黄十六, 赵十七, 吴十八, 周十九, 徐二十, 孙二十一, 马二十二, 朱二十三, 胡二十四, 林二十五, 郭二十六, 何二十七, 高二十八, 罗二十九, 郑三十</textarea>
                <p class="example-text">提示：您可以输入人名（用逗号或换行分隔）或学号范围（如1-40）</p>
            </div>
            
            <div class="settings">
                <div class="setting-item">
                    <label for="drawCount">每次抽取人数：</label>
                    <select id="drawCount">
                        <option value="1">1人</option>
                        <option value="2">2人</option>
                        <option value="3">3人</option>
                        <option value="4">4人</option>
                        <option value="5">5人</option>
                        <option value="6">6人</option>
                        <option value="7">7人</option>
                        <option value="8">8人</option>
                        <option value="9">9人</option>
                        <option value="10">10人</option>
                    </select>
                </div>
            </div>
        </div>
        
        <div class="button-group">
            <button id="startBtn" class="btn btn-primary">
                <i class="fas fa-play"></i> 开始抽取
            </button>
            <button id="changeListBtn" class="btn btn-secondary">
                <i class="fas fa-sync"></i> 更换名单
            </button>
        </div>
        
        <div class="card">
            <div class="result-container" id="resultContainer">
                <h2 class="result-title"><i class="fas fa-trophy"></i> 抽中名单</h2>
                <div class="result-display" id="resultDisplay"></div>
                
                <div class="button-group">
                    <button id="drawAgainBtn" class="btn btn-primary">
                        <i class="fas fa-redo"></i> 再次抽取
                    </button>
                    <button id="backToListBtn" class="btn btn-secondary">
                        <i class="fas fa-arrow-left"></i> 返回名单
                    </button>
                </div>
            </div>
        </div>
    </div>
    
    <footer>
        <p>课堂随机抽人系统 &copy; 2023 | 让课堂互动更高效 | 无音效版</p>
    </footer>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 获取DOM元素
            const nameListInput = document.getElementById('nameList');
            const drawCountSelect = document.getElementById('drawCount');
            const startBtn = document.getElementById('startBtn');
            const changeListBtn = document.getElementById('changeListBtn');
            const drawAgainBtn = document.getElementById('drawAgainBtn');
            const backToListBtn = document.getElementById('backToListBtn');
            const resultContainer = document.getElementById('resultContainer');
            const resultDisplay = document.getElementById('resultDisplay');
            
            // 当前名单数组
            let currentList = [];
            
            // 解析名单输入
            function parseNameList(input) {
                let names = [];
                
                // 处理学号范围格式 (如 1-40)
                const rangeRegex = /(\d+)\s*-\s*(\d+)/;
                const rangeMatch = input.match(rangeRegex);
                
                if (rangeMatch) {
                    const start = parseInt(rangeMatch[1]);
                    const end = parseInt(rangeMatch[2]);
                    
                    if (!isNaN(start) && !isNaN(end) && start <= end) {
                        for (let i = start; i <= end; i++) {
                            names.push(i + '号');
                        }
                        return names;
                    }
                }
                
                // 处理逗号分隔或换行分隔的名单
                const lines = input.split(/[\n,，]+/);
                
                for (let line of lines) {
                    const trimmed = line.trim();
                    if (trimmed) {
                        names.push(trimmed);
                    }
                }
                
                return names;
            }
            
            // 随机抽取函数
            function drawRandomNames(count) {
                if (currentList.length === 0) return [];
                if (count >= currentList.length) return [...currentList];
                
                const result = [];
                const tempList = [...currentList];
                
                for (let i = 0; i < count; i++) {
                    if (tempList.length === 0) break;
                    
                    const randomIndex = Math.floor(Math.random() * tempList.length);
                    result.push(tempList[randomIndex]);
                    tempList.splice(randomIndex, 1);
                }
                
                return result;
            }
            
            // 显示结果
            function showResults(names) {
                resultDisplay.innerHTML = '';
                
                names.forEach(name => {
                    const nameElement = document.createElement('div');
                    nameElement.className = 'result-item';
                    nameElement.textContent = name;
                    resultDisplay.appendChild(nameElement);
                });
                
                resultContainer.style.display = 'block';
            }
            
            // 开始抽取
            startBtn.addEventListener('click', function() {
                // 解析名单
                currentList = parseNameList(nameListInput.value);
                
                if (currentList.length === 0) {
                    alert('请输入有效的名单！');
                    return;
                }
                
                // 获取抽取人数
                const drawCount = parseInt(drawCountSelect.value);
                
                // 添加旋转动画
                const originalHTML = startBtn.innerHTML;
                startBtn.innerHTML = '<i class="fas fa-spinner spinning"></i> 抽取中...';
                startBtn.disabled = true;
                
                // 模拟抽取过程
                setTimeout(() => {
                    const result = drawRandomNames(drawCount);
                    showResults(result);
                    
                    // 恢复按钮状态
                    startBtn.innerHTML = originalHTML;
                    startBtn.disabled = false;
                }, 1200);
            });
            
            // 更换名单
            changeListBtn.addEventListener('click', function() {
                resultContainer.style.display = 'none';
                nameListInput.focus();
            });
            
            // 再次抽取
            drawAgainBtn.addEventListener('click', function() {
                if (currentList.length === 0) {
                    alert('名单为空，请重新设置名单！');
                    return;
                }
                
                // 获取抽取人数
                const drawCount = parseInt(drawCountSelect.value);
                
                // 添加旋转动画
                const originalHTML = drawAgainBtn.innerHTML;
                drawAgainBtn.innerHTML = '<i class="fas fa-spinner spinning"></i> 抽取中...';
                drawAgainBtn.disabled = true;
                
                // 模拟抽取过程
                setTimeout(() => {
                    const result = drawRandomNames(drawCount);
                    showResults(result);
                    
                    // 恢复按钮状态
                    drawAgainBtn.innerHTML = originalHTML;
                    drawAgainBtn.disabled = false;
                }, 1200);
            });
            
            // 返回名单
            backToListBtn.addEventListener('click', function() {
                resultContainer.style.display = 'none';
            });
            
            // 初始化示例名单
            nameListInput.value = "张三, 李四, 王五, 赵六, 钱七, 孙八, 周九, 吴十, 郑十一, 王十二, 刘十三, 陈十四, 杨十五, 黄十六, 赵十七, 吴十八, 周十九, 徐二十, 孙二十一, 马二十二, 朱二十三, 胡二十四, 林二十五, 郭二十六, 何二十七, 高二十八, 罗二十九, 郑三十";
        });
    </script>
</body>
</html>